From 349d3745d33362148579094f1d3c68a6091f04ae Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Fri, 14 Oct 2005 16:01:11 +0100 Subject: [PATCH] In addition to setting opaque handle during domain creation, allow it to be changed after creation via DOM0_SETDOMAINHANDLE operation (and libxc xc_domain_sethandle, and via Pyhton wrapper fn). Signed-off-by: Keir Fraser --- tools/libxc/xc_domain.c | 10 +++++++ tools/libxc/xenctrl.h | 2 ++ tools/python/xen/lowlevel/xc/xc.c | 49 +++++++++++++++++++++++++++++++ xen/common/dom0_ops.c | 15 ++++++++++ xen/include/public/dom0_ops.h | 6 ++++ 5 files changed, 82 insertions(+) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 6404b3f307..4b43ed9bf9 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -334,6 +334,16 @@ int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max) return do_dom0_op(xc_handle, &op); } +int xc_domain_sethandle(int xc_handle, uint32_t domid, + xen_domain_handle_t handle) +{ + dom0_op_t op; + op.cmd = DOM0_SETDOMAINHANDLE; + op.u.setdomainhandle.domain = (domid_t)domid; + memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t)); + return do_dom0_op(xc_handle, &op); +} + /* * Local variables: * mode: C diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index a5bfb62ac8..464810edf5 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -257,6 +257,8 @@ long long xc_domain_get_cpu_usage(int xc_handle, domid_t domid, int vcpu); +int xc_domain_sethandle(int xc_handle, uint32_t domid, + xen_domain_handle_t handle); typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t; int xc_shadow_control(int xc_handle, diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 4108e1ff30..bd554284ff 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -242,6 +242,47 @@ static PyObject *pyxc_domain_setcpuweight(PyObject *self, return zero; } +static PyObject *pyxc_domain_sethandle(PyObject *self, + PyObject *args, + PyObject *kwds) +{ + XcObject *xc = (XcObject *)self; + + int i; + uint32_t dom; + PyObject *pyhandle; + xen_domain_handle_t handle; + + static char *kwd_list[] = { "dom", "handle", NULL }; + + if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iO", kwd_list, + &dom, &pyhandle) ) + return NULL; + + if ( !PyList_Check(pyhandle) || + (PyList_Size(pyhandle) != sizeof(xen_domain_handle_t)) ) + { + out_exception: + errno = EINVAL; + PyErr_SetFromErrno(xc_error); + return NULL; + } + + for ( i = 0; i < sizeof(xen_domain_handle_t); i++ ) + { + PyObject *p = PyList_GetItem(pyhandle, i); + if ( !PyInt_Check(p) ) + goto out_exception; + handle[i] = (uint8_t)PyInt_AsLong(p); + } + + if ( xc_domain_sethandle(xc->xc_handle, dom, handle) < 0 ) + return PyErr_SetFromErrno(xc_error); + + Py_INCREF(zero); + return zero; +} + static PyObject *pyxc_domain_getinfo(PyObject *self, PyObject *args, PyObject *kwds) @@ -873,6 +914,14 @@ static PyMethodDef pyxc_methods[] = { " cpuweight [float, 1]: VCPU being pinned.\n" "Returns: [int] 0 on success; -1 on error.\n" }, + { "domain_sethandle", + (PyCFunction)pyxc_domain_sethandle, + METH_VARARGS | METH_KEYWORDS, "\n" + "Set domain's opaque handle.\n" + " dom [int]: Identifier of domain.\n" + " handle [list of 16 ints]: New opaque handle.\n" + "Returns: [int] 0 on success; -1 on error.\n" }, + { "domain_getinfo", (PyCFunction)pyxc_domain_getinfo, METH_VARARGS | METH_KEYWORDS, "\n" diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index d1d2bfcefa..9541adbbf8 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -557,6 +557,21 @@ long do_dom0_op(dom0_op_t *u_dom0_op) } break; + case DOM0_SETDOMAINHANDLE: + { + struct domain *d; + ret = -ESRCH; + d = find_domain_by_id(op->u.setdomainhandle.domain); + if ( d != NULL ) + { + memcpy(d->handle, op->u.setdomainhandle.handle, + sizeof(xen_domain_handle_t)); + put_domain(d); + ret = 0; + } + } + break; + #ifdef PERF_COUNTERS case DOM0_PERFCCONTROL: { diff --git a/xen/include/public/dom0_ops.h b/xen/include/public/dom0_ops.h index 528f9afc69..9402feb30e 100644 --- a/xen/include/public/dom0_ops.h +++ b/xen/include/public/dom0_ops.h @@ -405,6 +405,11 @@ typedef struct { unsigned int max; /* maximum number of vcpus */ } dom0_max_vcpus_t; +#define DOM0_SETDOMAINHANDLE 44 +typedef struct { + domid_t domain; + xen_domain_handle_t handle; +} dom0_setdomainhandle_t; typedef struct { uint32_t cmd; @@ -443,6 +448,7 @@ typedef struct { dom0_platform_quirk_t platform_quirk; dom0_physical_memory_map_t physical_memory_map; dom0_max_vcpus_t max_vcpus; + dom0_setdomainhandle_t setdomainhandle; uint8_t pad[128]; } u; } dom0_op_t; -- 2.30.2